package indi.gao;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c)2019$</p>
 * <p>Company: Tope</p>
 * <P>Created Date :2019$-08$-30$</P>
 * <P>@version 1.0</P>
 * todo 强制类型转换测试
 * todo long数据转化成int 截取前32 位数据进行计算 大于32数据的部分直接忽略
 */
public class LongMuturalInt {
    public static Date getDate(String dateStr) {
        if (dateStr.length() == 0) {
            return null;
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = df.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static String getYestoday(String sourceDate) {
        return getFormatDateAdd(getDate(sourceDate), -1);
    }

    public static String getTomorrow(String sourceDate) {
        return getFormatDateAdd(getDate(sourceDate), 1);
    }

    public static String getFormatDateAdd(Date date, int amount) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.add(GregorianCalendar.DATE, amount);
        return getDateString(cal.getTime());
    }

    /**
     * 按日期得到字符串，格式为 yyyy-MM-dd
     *
     * @param date 日期
     * @return
     */
    public static String getDateString(Date date) {
        return new SimpleDateFormat("yyyy-MM-dd").format(date);
    }

    public static void main(String[] args) {
        /*long longNum = 4444456546546544545L;
        Integer inNum = 456;
        int value = (int)longNum;
        System.out.println(value);
        System.out.println(Long.MAX_VALUE);
        System.out.println(Integer.MAX_VALUE);
        System.out.println(Long.toBinaryString(Long.MAX_VALUE));
        System.out.println(Long.toBinaryString(Long.MIN_VALUE));
        System.out.println(Long.toBinaryString(longNum));
        System.out.println(Long.parseLong("01111111111111111111111111111111",2));
        System.out.println(Integer.MAX_VALUE);
        System.out.println();*/
        System.out.println(20181223 / 10000);
        // System.out.println(trans);
        System.out.println(getYestoday("2018-03-23"));
        System.out.println(getTomorrow("2018-03-23"));

    }

}
